﻿/**
 * Jean-François Desgagné 2009 Portfolio
 * Copyright (c) 2009 Jean-François Desgagné <jfesgagne@gmail.com>
 * 
 * This work is licensed under a Creative Commons Attribution 3.0 United States License.
 * Some Rights Reserved.
 */
package com.jfdesgagne.jfdesgagne09.shell.view {
    import com.jfdesgagne.jfdesgagne09.shell.ApplicationFacade;
    import com.jfdesgagne.jfdesgagne09.shell.view.component.Site;
    import com.jfdesgagne.jfdesgagne09.shell.view.component.Background;
	import flash.events.Event;
    
    import flash.display.Stage;
	import flash.display.StageAlign;
    import flash.events.MouseEvent;
    
    import org.puremvc.as3.multicore.interfaces.*;
    import org.puremvc.as3.multicore.patterns.mediator.Mediator;
    
    public class StageMediator extends Mediator implements IMediator {
        // Cannonical name of the Mediator
        public static const NAME:String = "StageMediator";

        public function StageMediator(viewComponent:Object) {
			super(NAME, viewComponent);
        }
		
		public static function getInstance():StageMediator {
			return ApplicationFacade.getInstance(ApplicationFacade.NAME).retrieveMediator(StageMediator.NAME) as StageMediator;
		}
		
		override public function listNotificationInterests():Array {
            return [ 
            		ApplicationFacade.INITIALIZE
                   ];
        }

        override public function handleNotification(note:INotification):void {
            switch (note.getName()) {
            	case ApplicationFacade.INITIALIZE:    	
					this.initializeStage();
                break;
            }
        }
        
		private function resizeHandler(event:Event):void {
			sendNotification(ApplicationFacade.RESIZE);
		}
		
        private function initializeStage():void {
			this.stage.addEventListener(Event.RESIZE, this.resizeHandler);
			this.stage.align = StageAlign.TOP_LEFT;
        }

		public function get stage():Stage {
            return this.viewComponent as Stage;
        }
    }
}